using System.Collections.Generic;
using Token = TBit.Compile.ASMCompile.Token;
using TBit.Compile;

namespace TBit.Instrcutions {
    public static class DF {
    
        public static int Compile(List<Token> tokens,VM vm,int i) {
            return ASMCompile.StructureInstruction_OPCODE_V_D(Opcode.DF,tokens,vm,i);
        }
        public static Instruction Create(string a,Data b) {
            Instruction inst = new Instruction();
            inst.opcode = Opcode.DF;
            inst.args.Add(new InstructionArgData(a));
            inst.args.Add(new InstructionArgData(b));
            return inst;
        }

        public static int Run(VM vm,Instruction inst){
            InstructionArgData arg1 = inst.args[0];
            InstructionArgData arg2 = inst.args[1];
            
            string variable_name = arg1.variable;

            Function func = new Function();
            func.start_address = vm.pc + 1;
            func.end_address = (int)arg2.data.number_data;
            vm.WriteData(variable_name,new Data(func));

            vm.pc = (int)arg2.data.number_data;
            return 0;
        }
    }
}